#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
用户接口测试
"""

__author__ = 'Lei Chen'
__vsersion__ = '1.0'

import argparse
from testcase.test_login import *

# 安装日志
setup_logging()


# 入口函数
def main():
    parser = argparse.ArgumentParser(description='These are common testcase commands used in various situations:')

    parser.add_argument('cmd',
                        choices=['login', 'reg'],
                        help='支持命令：[login] 登录测试 [reg] 注册测试')

    parser.add_argument('name', default=None, nargs='?',
                        help='名称')

    parser.add_argument('num', default=None, nargs='?',
                        help='数量')

    # 参数解析
    args = parser.parse_args()

    if args.cmd:
        # 分组指令
        if args.cmd == 'login':
            logging.info('-----------------start------------------')
            usernames = [i for i in range(20000000200, 20000000211)]
            pool = threadpool.ThreadPool(10)
            requests = threadpool.makeRequests(login, usernames)
            [pool.putRequest(req) for req in requests]
            pool.wait()
            logging.info('-----------------——end-------------------')
        # 项目
        elif args.cmd == 'reg':
            print(args.name, args.num)
        else:
            error('[{0}]: 命令不支持'.format(args.cmd))


def error(msg):
    logging.error(msg)


def info(msg):
    logging.info(msg)


if __name__ == '__main__':
    main()
